package khleuven.mondzorg.db.googlespreadsheet;

import java.io.IOException;
import java.util.LinkedHashMap;

import junit.framework.TestCase;
import khleuven.mondzorg.db.DBException;
import khleuven.mondzorg.db.readers.EntryBuilderFactory;
import khleuven.mondzorg.db.readers.EntryBuilderType;
import khleuven.mondzorg.domain.DentalCareApp;
import khleuven.mondzorg.domain.DomainException;
import khleuven.mondzorg.domain.EntryType;

public class EntryBuilderOnlineTest extends TestCase {

	@Override
	protected void setUp() throws Exception {
		super.setUp();
	}

	public void testLoginPostRequest() throws DomainException, DBException, IOException {
		DentalCareApp dca = DentalCareApp.getInstance();
		
		int before = dca.getNbOfIllustrations();
		EntryBuilderFactory.createEntryBuilderAndLoad(EntryBuilderType.ONLINE);
		int after = dca.getNbOfIllustrations();
		
		assertTrue(before <= after);
		
		if(before == 0) {
			assertTrue("We should have at minimum 5 illustrations in the app", 5 <= after);
		}
		
		LinkedHashMap<EntryType, Integer> ebefore = dca.getNbOfEntriesPerType();
		if(ebefore.isEmpty()) {
			ebefore.put(EntryType.DEFINITION, 0);
			ebefore.put(EntryType.FAQ, 0);
			ebefore.put(EntryType.LEARN, 0);
			ebefore.put(EntryType.TEST, 0);
			
		}
		
		LinkedHashMap<EntryType, Integer> eafter = dca.getNbOfEntriesPerType();
		for(EntryType t : ebefore.keySet()) {
			if(!eafter.containsKey(t)) {
				fail("We should have at minimum 1 entry for type "+t.toString()+" in the app");
			}
			assertTrue("We should have at minimum equal or more entries for type "+t.toString()+" in the app",ebefore.get(t) <= eafter.get(t));
			assertTrue("We should have at minimum 5 for type "+t.toString()+" in the app",eafter.get(t) > 5);
		}		
	}

}
